package com.zxy.activemqjms;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author zhangxuyuan
 * @version 1.0
 * @date 2020/11/22
 */
public class TopicProducer {

    public static void main(String[] args) throws JMSException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");

        Connection connection = connectionFactory.createConnection();

        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Topic topic1 = session.createTopic("topic1");

        MessageProducer producer = session.createProducer(topic1);

      for(int i=0;i<15;i++)
      {
          TextMessage hello_topic1 = session.createTextMessage("hello topic1-----"+i);

          producer.send(hello_topic1);

          System.out.println("消息已发送"+"hello topic1-----"+i);
      }
    }
}
